import { Controller, Get, Post, Put, Body, Patch, Param, Delete, Query, Request } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBody, ApiConsumes, ApiQuery, ApiBearerAuth } from '@nestjs/swagger';
import { KzService } from './kz.service';
import { CreateAccountDto } from './dto/create-account.dto';
import { UpdateAccountDto } from './dto/update-account.dto';
import { ListAccountDto } from './dto/list-account.dto';
import { UpdateSiteDto } from './dto/update-site.dto';
import { ListSiteDto } from './dto/list-site.dto';

@ApiTags('快站管理')
@Controller('kz')
export class KzController {
  constructor(private readonly kzService: KzService) {}
  
  /* 快站账号相关接口 */
  // =======================================================
  // 添加快站账号 
  @ApiOperation({summary: '快站管理-添加账号',})
  @ApiBody({
    type: CreateAccountDto,
    required: true,
  })
  @Post('/account/add')
  createAccount(@Request() req, @Body() CreateAccountDto: CreateAccountDto) {
    let user = req.user
    return this.kzService.createAccount(user, CreateAccountDto);
  }

  // 修改快站账号信息
  @Post('/account/edit')
  updateAccount(@Request() req, @Body() UpdateAccountDto: UpdateAccountDto) {
    let user = req.user
    return this.kzService.updateAccount(user, UpdateAccountDto);
  }

  // 账号列表查询
  @Get('/account/list')
  findAccounts(@Query() ListAccountDto:ListAccountDto) {
    return this.kzService.findAccounts(ListAccountDto);
  }

  // 同步账号下所有站点到数据库
  @Get('/account/sync/:id')
  accountSyncSites(@Param('id') id:number) {
    return this.kzService.accountSyncSites(id)
  }
  // =======================================================

  /* 快站站点相关接口 */
  // =======================================================
  // 站点列表查询
  @Get('/site/list')
  findSites(@Query() ListSiteDto: ListSiteDto) {
    return this.kzService.findSites(ListSiteDto)
  }

  // 更新快站站点(域名、页面内容)
  @Post('/site/edit')
  updateSite(@Body() UpdateSiteDto: UpdateSiteDto) {
    return this.kzService.updateSite(UpdateSiteDto);
  }

  // 检查站点域名是否被微信封禁
  @Get('/site/checkBan')
  siteCheckBan(@Query('siteId') siteId: string) {
    return this.kzService.checkSiteDomainBan(siteId);
  }

  // 查询站点修改历史
  @Get('/site/history')
  findSiteHistorys(@Query() query) {
    return this.kzService.findSiteHistory(query)
  }

  // 查询站点域名页面内容
  @Get('/site/content')
  findSiteContent(@Query('siteId') siteId: string) {
    return this.kzService.findSiteContent(siteId);
  }
  // 同步单个站点到数据库
  @Get('/site/sync')
  siteSync(@Request() req, @Query('siteId') siteId: string) {
    let user = req.user
    return this.kzService.siteSync(user, siteId);
  }

  // =======================================================

}
